package com.huangc.cn.rainbow.util;

import com.huangc.cn.rainbow.constant.Constant;
import com.huangc.cn.rainbow.properties.CityConfig;
import com.huangc.cn.rainbow.spring.SpringContextHolder;

import java.util.Random;

/**
 * @author huangc
 */
public class AppRandom {

    private static Random random = new Random();

    private static CityConfig cityConfig = SpringContextHolder.getBean(CityConfig.class);

    public static String getDistinctId() {
        return "e8fbf16c3cec" + String.format("%05d", random.nextInt(99999));
    }

    public static String getDeviceId() {
        return "e8fbf16c3cer" + String.format("%05d", random.nextInt(99999));
    }

    public static String getLoginId(){
        return String.format("%05d", random.nextInt(99999));
    }
    public static String getSessionId() {
        return "e8fbf16c3cec" + String.format("%05d", random.nextInt(99999));
    }

    public static String getProvince() {
        return cityConfig.getProvinces()[random.nextInt(cityConfig.getProvinces().length)];
    }

    public static String getCity(String province) {
        String[] city = cityConfig.getCity(province);
        return city[random.nextInt(city.length )];
    }

    public static String getVersion() {
        return Constant.versions[random.nextInt(Constant.versions.length )];
    }

    public static String getChannel() {
        return Constant.channels[random.nextInt(Constant.channels.length )];
    }

    public static String getAppId() {
        return Constant.appIds[random.nextInt(Constant.appIds.length)];
    }

    public static String getPage(){
        return Constant.currentPages[random.nextInt(Constant.currentPages.length )];
    }
    public static String getRefPage(){
        return Constant.refPages[random.nextInt(Constant.refPages.length)];
    }
    public static String getModel() {
        return Constant.models[random.nextInt(Constant.models.length )];
    }
    public static String getBand(){
        return Constant.bands[random.nextInt(Constant.bands.length)];
    }

    public static String getName(){
        return Constant.name[random.nextInt(Constant.name.length)];
    }

    public static String getSex(){
        return Constant.sex[random.nextInt(Constant.sex.length)];
    }

    public static String getAge(){
        return Constant.age[random.nextInt(Constant.age.length)];
    }

    public static String getCustomer_number(){
        return Constant.customer_number[random.nextInt(Constant.customer_number.length)];
    }

    public static String getPhone_num(){
        return Constant.phone_num[random.nextInt(Constant.phone_num.length)];
    }

    public static String getAffiliation(){
        return Constant.affiliation[random.nextInt(Constant.affiliation.length)];
    }


    /**
     * 获取相关事件
     * @return
     */
    public static String getEvent() {
        int chance=random.nextInt(20);
        if(chance<10){
//            return Constant.defineEvents[random.nextInt(Constant.defineEvents.length )];//理财
            return Constant.transferEvents[random.nextInt(Constant.transferEvents.length )];//转账
        }else if(chance<12){
           return Constant.exceptionEvents[random.nextInt(Constant.exceptionEvents.length )];
        }  else{
            return Constant.events[random.nextInt(Constant.events.length )];
        }

    }
    /**
     * 获取崩溃事件的原因
     */
    public static String getCrashedReason(){
        return Constant.crashedReason[random.nextInt(Constant.crashedReason.length)];
    }

    /**
     * 获取安卓卡死事件原因
     */
    public static String getAndroidFreezingReason(){
        return Constant.androidFreezingReason[random.nextInt(Constant.androidFreezingReason.length)];
    }
    /**
     * 获取iOS卡死原因
     */
    public static String getIosFreezingReason(){
        return Constant.iosFreezingReason[random.nextInt(Constant.iosFreezingReason.length)];
    }

    /**
     * 获取URL
     */
    public static String getUrl(){
        return Constant.urls[random.nextInt(Constant.urls.length)];
    }

    /**
     * 获取网络类型
     */
    public static String getNetworktype(){
        return Constant.network_type[random.nextInt(Constant.network_type.length)];
    }

    /**
     * 获取状态码
     */
    public static int getStatusCode(){
        return Constant.statusCodes[random.nextInt(Constant.statusCodes.length)];
    }

    /**
     * 获取错误码
     */
    public static int getErrorCode(){
        return Constant.errorCodes[random.nextInt(Constant.errorCodes.length)];
    }

    /**
     * 获取错误码
     */
    public static String getProcessName(){
        return Constant.processNames[random.nextInt(Constant.processNames.length)];
    }

    /**
     * 获取错误描述
     */
    public static String getErrorDetail(){
        return Constant.errorDetail[random.nextInt(Constant.errorDetail.length)];
    }
    /**
     * 获取运营商
     */
    public static String getCarrier(){
        return Constant.carrier[random.nextInt(Constant.carrier.length)];
    }
}
